package com.huangkailong.designpattern.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 票工厂.
 *
 * @author huangkl
 * @since 1.0.0
 */
public class TicketFactory {
    private static final Map<String, ITicket> TICKET_POOL = new ConcurrentHashMap<>(10);

    /**
     * 查询票.
     *
     * @param from 出发地
     * @param to   目的地
     * @return {@link ITicket}
     */
    public static ITicket queryTicket(String from, String to) {
        String key = from + "-->" + to;
        return TICKET_POOL.computeIfAbsent(key, k -> new TrainTicket(from, to));
    }
}
